package com.ustb.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.JwtUtil;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.common.utils.TokenUtil;
import com.ustb.springboot.controller.dto.UserDto;
import com.ustb.springboot.entity.*;
import com.ustb.springboot.service.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @author pyn
 * @date 2022/5/6 - 21:15
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    @RequiresPermissions("user:login")
    public R login(@RequestBody UserDto userDto) {
        return userService.login(userDto);
    }


    @RequestMapping("/info")
    @RequiresPermissions("user:info")
    public R info(HttpServletRequest request) {
        return userService.getInfo(request);
    }


    //注册
    @RequestMapping("/register")
    @RequiresPermissions("user:register")
    public R register(@RequestBody UserEntity userEntity) {
        return userService.register(userEntity);
    }

    @RequestMapping("/logout")
    @RequiresPermissions("user:logout")
    public R logout() {
        return R.ok(20000, "注销登录成功");
    }

}
